package com.powernode.mapper;

import com.powernode.pojo.Lend;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 繁寂
 * @version 1.0
 * @since 1.0
 */
@Mapper
public interface LendMapper {

    @Select("select * from t_lend")
    @Results({
        @Result(property = "userId", column = "user_id"),
        @Result(property = "userName", column = "user_name"),
        @Result(property = "bookId", column = "book_id"),
        @Result(property = "bookName", column = "book_name"),
        @Result(property = "bookNum", column = "book_num"),
    })
    List<Lend> selLendAll();

    @Select("select * from t_lend where user_name=#{userName}")
    @Results({
            @Result(property = "userId", column = "user_id"),
            @Result(property = "userName", column = "user_name"),
            @Result(property = "bookId", column = "book_id"),
            @Result(property = "bookName", column = "book_name"),
            @Result(property = "bookNum", column = "book_num"),
    })
    List<Lend> selLendByUserName(String userName);

    @Insert("insert into t_lend value(null,#{userId},#{userName},#{bookId},#{bookName},#{bookNum})")
    Integer insertLend(Lend lend);

    @Update("update t_lend set id=#{id}, user_id=#{userId}, user_name=#{userName}, book_id=#{bookId}, book_name=#{bookName}, book_num=#{bookNum} where id=#{id}")
    Integer updateLend(Lend lend);

    @Delete("delete from t_lend where id=#{id}")
    Integer deleteLend(Lend lend);

}
